<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 字典表操作ajax类
 * @package  ajax
 * @subpackage  backend
 * @author   create by allen.qiang
 */



class ajax_item {
	
	public function execute () {
		if (isset($_REQUEST['operFlg'])) {
			$operFlg = $_REQUEST['operFlg'];
			
			switch ($operFlg) {
				case 1:
					$this->searchItem();
					break;
				case 2:
					$this->saveItem();
					break;
				case 3:
					$this->deleteItem();
					break;
			}
		}
	}
	
	/**
	 * 查询字典信息
	 * @author raohenglei
	 * 
	 */
	private function searchItem () {
		global $G_PGLOB;
		
		//实例化字典表操作类
		$itemHandler = new itemHandler( $G_PGLOB->DBCA );
		
		//调用查询字典信息方法
		$itemList = $itemHandler->searchItemList( $_REQUEST );
		
		$itemCategoryID = $_REQUEST['item'];
		
		//组织返回的数据
        $result_array = array(
            'page' => $_REQUEST['page'],
            'total' => $_REQUEST['count'],
            'rows' => array()
        );
        
        if ($itemList) {
            foreach($itemList as &$item) {
                $result_array['rows'][] = array(
                    'id' => $item->itemID,
                    'cell' => array(
                        '<a href="javascript: void(0);" onclick="item.edit('.$itemCategoryID.','.$item->itemID.')">修改</a>',
                        $item->itemID,
                        $item->itemName,
                        $item->useFlg == 1 ? '使用' : '禁用'
                    )
                );
            }
        }
		
		echo json_encode( $result_array );
	}
	
	/**
	 * 修改字典表信息
	 *
	 */
	private function saveItem() {
		global $G_PGLOB;
		
		//实例化字典表操作类
		$itemHandler = new itemHandler( $G_PGLOB->DBCA );
		
		$_REQUEST['creator'] = $G_PGLOB->currentUserID;
		
		//保存信息
        $result_array = $itemHandler->itemSave( $_REQUEST );

        echo json_encode( $result_array );
		
	}
	
	/**
	 * 删除字典表信息
	 *
	 */
	private function deleteItem(){
		global $G_PGLOB;
		
		//实例化字典表操作类
		$itemHandler = new itemHandler( $G_PGLOB->DBCA );
		
		//调用字典表信息删除方法
		$result_array = $itemHandler->deleteItem( $_REQUEST );

		echo json_encode( $result_array );
	}
}